package com.bankwel.j3d.model;

import java.awt.Graphics2D;

import com.bankwel.j3d.core.J3dMatrix;

public class Pyramid extends Object3d {

	private float length;
	private float height;

	public Pyramid(J3dMatrix j3d, float length, float height) {
		super(j3d);
		this.length = length;
		this.height = height;
	}

	@Override
	public void draw(Graphics2D g2d) {
		// TODO
		Vector3d origin = new Vector3d(0, 0, 0);
		Vector3d[] v = new Vector3d[5];
		v[0] = origin.add(-length / 2, -length / 2, 0).transform(getJ3d());
		v[1] = origin.add(-length / 2, length / 2, 0).transform(getJ3d());
		v[2] = origin.add(length / 2, length / 2, 0).transform(getJ3d());
		v[3] = origin.add(length / 2, -length / 2, 0).transform(getJ3d());
		v[4] = origin.add(0, 0, height).transform(getJ3d());

		Dot[] d = new Dot[5];
		for (int i = 0; i < 5; i++)
			d[i] = v[i].to2d();

		drawLine(d, 0, 1, g2d);
		drawLine(d, 1, 2, g2d);
		drawLine(d, 2, 3, g2d);
		drawLine(d, 3, 0, g2d);

		drawLine(d, 0, 4, g2d);
		drawLine(d, 1, 4, g2d);
		drawLine(d, 2, 4, g2d);
		drawLine(d, 3, 4, g2d);
	}

	private void drawLine(Dot[] set, int from, int to, Graphics2D g) {
		g.drawLine((int) set[from].getX(), (int) set[from].getY(), (int) set[to].getX(), (int) set[to].getY());
	}

}
